package com.bo.Service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bo.Dao.CompanyDao;
import com.bo.Entity.Company;
import com.bo.Entity.MyImage;
import com.bo.Entity.MyPage;
import com.bo.Entity.Product;
import com.bo.Service.CompanyService;


@Service
public class CompanyServiceImpl implements CompanyService{

	@Autowired
	private CompanyDao companyDao;
	
	
	
	@Transactional(readOnly=true)
	public Company login(Company company){
		
		List<Company> list=companyDao.login(company.getAccount(), company.getPassword());
		
		if(list.size()==0){
			return null;
		}else{
			return list.get(0);
		}
	}
	
	@Transactional
	public boolean save(Company company){
		
		int num=companyDao.save(company);
		
		if(num>0)
			return true;
		else
			return false;
	}
	
	
	@Transactional(readOnly=true)
	public boolean checkAccount(String account){
		
		int num=companyDao.checkAccount(account);
		
		if(num>0)
			return true;
		else
			return false;
	}
	
	@Transactional(readOnly=true)
	public boolean createPage(String search,MyPage<Company> myPage){
		
	  try{
		  
		  long rowCount=companyDao.count();
		  myPage.setRowCount((int)rowCount);
		  List<Company> list=companyDao.getCompanyList(search, myPage);
		  myPage.setList(list);
		  
		  return true;
	
	  }catch(Exception e){
		  e.printStackTrace();
		  return false;
	  }
	}
	
	
	@Transactional(readOnly=true)
    public void getImage(int id, MyImage image){
    	 
    	 try{
 			
    		 companyDao.getImage(id, image);
  		   
  		}catch(EmptyResultDataAccessException e){
  			
  		}
     }
}
